package ua.edu.nuos.tees.jdmmon.threads;

import jssc.SerialPortException;
import ua.edu.nuos.tees.jdmmon.gui.GUI;

import java.io.IOException;

/**
 * @author Timur Yarosh
 *         Date: 20.05.13
 *         Time: 22:10
 */
public class DataUpdater implements Runnable {
    private GUI gui;
    private long updateTime;

    /**
     * Initialize fields
     * @param gui GUI
     * @param updateTime update time in ms
     */
    public DataUpdater(GUI gui, long updateTime) {
        this.gui = gui;
        this.updateTime = updateTime;
    }

    @Override
    public void run() {
        while (true) {
            try {
                gui.refreshGUI();
                //wait(updateTime);
                Thread.sleep(updateTime);
            } catch (InterruptedException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            } catch (SerialPortException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
    }
}
